//------------------------------------------------------------------------------ 
//      Copyright (c) 2005, Be Nanashi-San 
// 
//      Permission is hereby granted, free of charge, to any person obtaining a 
//      copy of this software and associated documentation files (the "Software"), 
//      to deal in the Software without restriction, including without limitation 
//      the rights to use, copy, modify, merge, publish, distribute, sublicense, 
//      and/or sell copies of the Software, and to permit persons to whom the 
//      Software is furnished to do so, subject to the following conditions: 
// 
//      The above copyright notice and this permission notice shall be included in 
//      all copies or substantial portions of the Software. 
// 
//      THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
//      IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
//      FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
//      AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
//      LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
//      FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
//      DEALINGS IN THE SOFTWARE. 
// 
//      File Name:   2chPositive.cpp
//      Author:      Be Nanashi-San 
//      Description: 2chPositive application class. 
//------------------------------------------------------------------------------
#if 0
//PrefClass案
//変数；各種ディレクトリを変数として保持。
//
BString fPrefDIr;
BString fBoardfDIr;
BString fChshefDIr;
// Directory info
GetPrefDir();
GetBoardDir();
GetChashDir();
//Get
bool GetBool(name)
BString GetString(name)
BRect GetRect(name)
BPoint GetPoint(name)
BMessage GetMessage(name)
//Replace & Set
SetBool(name, data)
SetString(name, data))
SetRect(name, data))
SetPOint(name, data)
SetMessage(name, data))

////////////////////////////////////////////////////////////////////////////////
// void a2chViewer::MakeSettingDir()
// 各種設定保存用ディレクトリを作成する。
//
////////////////////////////////////////////////////////////////////////////////
void
a2chViewer::MakeSettingDir()
{
	BPath path;
	find_directory(B_USER_SETTINGS_DIRECTORY, &path);

	BDirectory dir(path.Path());
	dir.CreateDirectory(kSETTING_DIR_NAME, &dir);
	path.Append(kSETTING_DIR_NAME);

	BDirectory subdir(path.Path());;
	subdir.CreateDirectory("BBS", &subdir);
	subdir.SetTo(path.Path());
	subdir.CreateDirectory("2chCache", &subdir);
	subdir.SetTo(path.Path());
	subdir.CreateDirectory("Bookmarks", &subdir);
}
////////////////////////////////////////////////////////////////////////////////
// status_t a2chViewer::LoadSetting()
// アプリの設定をファイルから読み込む。
// 成功すればB_OKを返す。
////////////////////////////////////////////////////////////////////////////////
status_t
a2chViewer::LoadSetting()
{
	BAutolock(this);
	BPath path;
	find_directory(B_USER_SETTINGS_DIRECTORY, &path);
	path.Append(kSETTING_DIR_NAME);
	path.Append(kSETTING_FILE_NAME);

	BFile loadfile;
	status_t status = loadfile.SetTo(path.Path(), B_READ_WRITE);
	if(status == B_OK){
		status = fSetting.Unflatten(&loadfile);
		// Add offline setting	
		fSetting.FindBool(kSETTING_OFFLINE, &fConection);
	}
	return status;
}
////////////////////////////////////////////////////////////////////////////////
// status_t a2chViewer::SaveSetting()
// アプリの設定をファイルに保存。
// 成功すればB_OKを返す。
////////////////////////////////////////////////////////////////////////////////
status_t
a2chViewer::SaveSetting()
{
	BAutolock(this);
	// Add offline setting	
	fSetting.ReplaceBool(kSETTING_OFFLINE, fConection);

	BPath path;
	find_directory(B_USER_SETTINGS_DIRECTORY, &path);
	path.Append(kSETTING_DIR_NAME);
	path.Append(kSETTING_FILE_NAME);
	BFile savefile(path.Path(), B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE);
	return fSetting.Flatten(&savefile);
}
////////////////////////////////////////////////////////////////////////////////
// void findcachedir
// 各種ファイルのあるディレクトリを返す。
//20050626: sprintfからBpath.Append()に変更
//20050707: Bpath.Append()からsprintfに変更
////////////////////////////////////////////////////////////////////////////////
void
findcachedir(BDirectory *cachedir, const char *dir, const char *uri/* = NULL*/)
{
	char path[B_PATH_NAME_LENGTH];

	BPath user_setting_path;
	find_directory(B_USER_SETTINGS_DIRECTORY, &user_setting_path);

	if(uri){
		sprintf(path, "%s/%s/%s", user_setting_path.Path(), dir, uri);
	}else{
		sprintf(path, "%s/%s", user_setting_path.Path(), dir);
	}
	
	BEntry ent(path);
	if(ent.Exists() == false){
		create_directory(path, 0777);	//0777は8進数
	}
	cachedir->SetTo(path);
}
#endif

